﻿using ExcelFileMonitor.NPOI.Config;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ExcelFileMonitor.NPOI
{
    public static class ConfigurationLoader
    {
        public static FileWatcherConfig LoadConfig(string configFile = "FileWatchsettings.json")
        {
            try
            {
                var configuration = new ConfigurationBuilder()
                    .SetBasePath(Directory.GetCurrentDirectory())
                    .AddJsonFile(configFile, optional: false, reloadOnChange: true)
                    .Build();

                var config = new FileWatcherConfig();
                configuration.GetSection("FileWatcherConfig").Bind(config);

                return config;
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException($"加载配置文件失败: {ex.Message}", ex);
            }
        }
    }
}
